完全日期

题目 完全日期

image-2536fbd3

思路分析

image-59f42742

代码实现

#include<bits/stdc++.h>

using namespace std;

#define endl '\n'

int days[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};

bool is_leap(int y){

	return y%100 && y%4==0 || y%400==0;

}

int get_days(int y,int m){

	return days[m]+(m==2 && is_leap(y));

}

void next_day(int &y,int &m,int &d){

	d++;

	if(d>get_days(y,m)){

		d=1;

		m++;

		if(m>12){

			m=1;

			y++;

		}

	}

}

int main()

{

	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);

	set<int> pn;

	for(int i=1;i*i<50;i++){

		pn.insert(i*i);

	}

	int cnt=0;

	int cury=2001,curm=1,curd=1;

	while(cury<2022){

		int tempy=cury,tempm=curm,tempd=curd;

		int sum=0;

		while(tempy){

			sum+=tempy%10;

			tempy/=10;

		}

		while(tempm){

			sum+=tempm%10;

			tempm/=10;

		}

		while(tempd){

			sum+=tempd%10;

			tempd/=10;

		}

		if(pn.count(sum))

			cnt++;

		next_day(cury,curm,curd);

	}

	cout<<cnt;

	return 0;

}

同类题型

视频讲解


⬅️ 纯质数 🏠 00-冲刺国赛 ➡️ 最小权值